var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2NodeManager = require("NodeManager");
var $2GameUser = require("GameUser");
var $2Platformconf = require("Platformconf");
var $2PlatformMgr = require("PlatformMgr");
var $2UIPLoadingFirst = require("UIPLoadingFirst");
var Adv_skd=require("./Adv_skd");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_gameBefore = /* */function (_cc$Component37) {
  function _ctor() {
    var _this168;
    babel_classCallCheck(this, _ctor);
    _this168 = _callSuper(this, _ctor, arguments);
    _this168.GameMain = null;
    _this168.prefab = null;
    _this168.IsBannerShow = false;
    _this168.IsCustomShow = false;
    _this168.jishuNum = 5;
    return _this168;
  }
  babel_inherits(_ctor, _cc$Component37);
  return babel_createClass(_ctor, [{
    key: "onLoad",
    value: function onLoad() {}
  }, {
    key: "start",
    value: function start() {

      Adv_skd.default.instance.getWxIdFromServer(()=>{
        this.onWindowResize();
        this.addpre();
        this.BannerShow();
        $2NodeManager.default.Instance.setCanvasNode(this.node);
        $2NodeManager.default.Instance.closeTiliView();
      },()=>{
        this.onWindowResize();
        this.addpre();
        this.BannerShow();
        $2NodeManager.default.Instance.setCanvasNode(this.node);
        $2NodeManager.default.Instance.closeTiliView();
      })

      
    }
  }, {
    key: "addpre",
    value: function addpre() {
      var _this169 = this;
      var e = cc.instantiate(this.prefab);
      e.parent = this.node;
      var t = e.getComponent($2UIPLoadingFirst.default);
      t.showLevelsUi();
      t.loadAll(function () {
        _this169.GameMain.active = true;
      });
    }
  }, {
    key: "onWindowResize",
    value: function onWindowResize() {
      cc.view.enableAutoFullScreen(true);
      if (cc.sys.isBrowser) {
        cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
        cc.view.enableAutoFullScreen(true);
      }
      var e = this.node.getComponent(cc.Canvas).fitWidth;
      if (cc.winSize.height / cc.winSize.width < 1334 / 750) {
        this.node.getComponent(cc.Canvas).fitWidth = false;
        this.node.getComponent(cc.Canvas).fitHeight = true;
      } else {
        this.node.getComponent(cc.Canvas).fitWidth = true;
        this.node.getComponent(cc.Canvas).fitHeight = false;
      }
      if (e != this.node.getComponent(cc.Canvas).fitWidth) {
        this.node.getComponent(cc.Widget).updateAlignment();
        this.node.getComponentsInChildren(cc.Widget).forEach(function (e) {
          e.updateAlignment();
        });
      }
    }
  }, {
    key: "BannerShow",
    value: function BannerShow() {
      var _this170 = this;
      this.CustomShow();
      console.log("this.IsBannerShow", this.IsBannerShow);
      if (this.IsBannerShow) {
        return;
      }
      console.log("是否新用户", $2GameUser.default.getInstance().IsNewPlayer);
      console.log("this.jishuNum:", this.jishuNum);
      if ($2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.WXGame && this.jishuNum > 0) {
        this.jishuNum--;
        return void this.scheduleOnce(function () {
          _this170.BannerShow();
        }, .1);
      }
      this.IsBannerShow = true;
      var e = this.node.getChildByName("banner").width;
      var t = this.node.getChildByName("banner").height;
      var n = this.node.getChildByName("banner").x + e / 2;
      var o = this.node.getChildByName("banner").y + this.node.height / 2;
      var i = new cc.Rect(n, o, e, t);
      console.log("rect--------------", i);
      $2PlatformMgr.default.Instance().bannerShow(0, i);
    }
  }, {
    key: "BannerHide",
    value: function BannerHide() {
      var _this171 = this;
      this.CustomHide();
      if ($2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.WXGame && this.jishuNum > 0) {
        this.jishuNum--;
        return void this.scheduleOnce(function () {
          _this171.BannerHide();
        }, .1);
      }
      this.IsBannerShow = false;
      $2PlatformMgr.default.Instance().bannerHide(0);
    }
  }, {
    key: "CustomShow",
    value: function CustomShow() {
      var _this172 = this;
      if (this.IsCustomShow) {
        return;
      }
      if ($2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.WXGame && this.jishuNum > 0) {
        return void this.scheduleOnce(function () {
          _this172.CustomShow();
        }, .1);
      }
      this.IsCustomShow = true;
      var e = this.node.getChildByName("custom").width;
      var t = this.node.getChildByName("custom").height;
      var n = this.node.getChildByName("custom").x;
      var o = this.node.getChildByName("custom").y - this.node.height / 4 - 25;
      var i = new cc.Rect(n, o, e, t);
      console.log("rect:", i);
      $2PlatformMgr.default.Instance().showCustomAd(0, i);
    }
  }, {
    key: "CustomHide",
    value: function CustomHide() {
      var _this173 = this;
      if ($2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.WXGame && this.jishuNum > 0) {
        this.scheduleOnce(function () {
          _this173.CustomHide();
        }, .1);
      } else {
        this.IsCustomShow = false;
        $2PlatformMgr.default.Instance().hideCustomAd(0);
      }
    }
  }]);
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_gameBefore.prototype, "GameMain", undefined);
cc__decorate([ccp_property(cc.Prefab)], def_gameBefore.prototype, "prefab", undefined);
def_gameBefore = cc__decorate([ccp_ccclass], def_gameBefore);
exports.default = def_gameBefore;